package com.wyj.config;



import com.wyj.component.LoginHandlerInterceptor;
import com.wyj.component.MyLocaleResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.*;

/**
 * Created by wuyj on 2018/7/1 0001.
 */
//@EnableWebMvc 标注的时候代表全面接管mvc
@Configuration
public class MyMvcConfig implements WebMvcConfigurer{
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        // super.addViewControllers(registry);
        registry.addViewController("/atguigu").setViewName("success");
    }

    @Bean
    public WebMvcConfigurer webMvcConfigurerAdapter() {
        WebMvcConfigurer adapter = new WebMvcConfigurer() {
            @Override
            public void addViewControllers(ViewControllerRegistry registry) {
                registry.addViewController("/").setViewName("login");
                registry.addViewController("/login.html").setViewName("login");
                registry.addViewController("/main.html").setViewName("dashboard");
            }

            @Override
            public void addInterceptors(InterceptorRegistry registry) {
                registry.addInterceptor(new LoginHandlerInterceptor()).addPathPatterns("/**")
                        .excludePathPatterns("/login.html","/","/login");
            }
        };
        return adapter;
    }



   /* @Override
    protected void addViewControllers(ViewControllerRegistry registry) {
      //  super.addViewControllers(registry);
        registry.addViewController("/atguigu").setViewName("success");
    }*/

   @Bean
   public LocaleResolver LocaleResolver() {
       return new MyLocaleResolver();
   }
}

